﻿namespace Smart.Utils.Shell
{
    using System;
    using System.IO;
    using System.Windows.Forms;

    public class MyLink
    {
        public static void Create(string LinkName, string TargetPath, string ExecutePath, string Description, string icon)
        {
            DirectoryInfo info = new DirectoryInfo(TargetPath);
            if (!info.Exists)
            {
                info.Create();
            }
            FileInfo info2 = new FileInfo(ExecutePath);
            string fileName = info.FullName + @"\" + LinkName + ".lnk";
            FileInfo info3 = new FileInfo(fileName);
            try
            {
                if (info3.Exists)
                {
                    info3.Delete();
                }
                ShellShortcut shortcut = new ShellShortcut(info3.FullName);
                shortcut.Path = ExecutePath;
                shortcut.Description = Description;
                shortcut.IconPath = icon;
                shortcut.Save();
            }
            catch
            {
                MessageBox.Show("Unable to create link in special directory: " + fileName, "Shell Link Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }

        public static void CreateInternet(string LinkName, string TargetPath, string ExecutePath, string Description, string icon)
        {
            DirectoryInfo info = new DirectoryInfo(TargetPath);
            if (!info.Exists)
            {
                info.Create();
            }
            string fileName = info.FullName + @"\" + LinkName + ".lnk";
            FileInfo info2 = new FileInfo(fileName);
            try
            {
                if (info2.Exists)
                {
                    info2.Delete();
                }
                ShellShortcut shortcut = new ShellShortcut(info2.FullName);
                shortcut.Path = ExecutePath;
                shortcut.WorkingDirectory = TargetPath;
                shortcut.Description = Description;
                shortcut.IconPath = icon;
                shortcut.Save();
            }
            catch
            {
                MessageBox.Show("Unable to create link in special directory: " + fileName, "Shell Link Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
    }
}

